package com.kotasoft.training.roogwteclipselink.client.managed.activity;

import com.google.gwt.activity.shared.Activity;
import com.google.gwt.activity.shared.ActivityMapper;
import com.google.gwt.place.shared.Place;
import com.google.gwt.place.shared.PlaceController;
import com.google.inject.Inject;

import com.kotasoft.training.roogwteclipselink.client.scaffold.place.ProxyListPlace;
import com.kotasoft.training.roogwteclipselink.client.managed.request.ApplicationRequestFactory;
import com.kotasoft.training.roogwteclipselink.client.managed.request.ApplicationEntityTypesProcessor;
import com.kotasoft.training.roogwteclipselink.client.scaffold.ScaffoldApp;
import com.kotasoft.training.roogwteclipselink.client.managed.activity.ProfesorListActivity;
import com.kotasoft.training.roogwteclipselink.client.managed.request.ProfesorProxy;
import com.kotasoft.training.roogwteclipselink.client.managed.ui.ProfesorListView;
import com.kotasoft.training.roogwteclipselink.client.managed.ui.ProfesorMobileListView;
import com.kotasoft.training.roogwteclipselink.client.managed.activity.MatriculaListActivity;
import com.kotasoft.training.roogwteclipselink.client.managed.request.MatriculaProxy;
import com.kotasoft.training.roogwteclipselink.client.managed.ui.MatriculaListView;
import com.kotasoft.training.roogwteclipselink.client.managed.ui.MatriculaMobileListView;
import com.kotasoft.training.roogwteclipselink.client.managed.activity.DireccionListActivity;
import com.kotasoft.training.roogwteclipselink.client.managed.request.DireccionProxy;
import com.kotasoft.training.roogwteclipselink.client.managed.ui.DireccionListView;
import com.kotasoft.training.roogwteclipselink.client.managed.ui.DireccionMobileListView;
import com.kotasoft.training.roogwteclipselink.client.managed.activity.DepartamentoListActivity;
import com.kotasoft.training.roogwteclipselink.client.managed.request.DepartamentoProxy;
import com.kotasoft.training.roogwteclipselink.client.managed.ui.DepartamentoListView;
import com.kotasoft.training.roogwteclipselink.client.managed.ui.DepartamentoMobileListView;
import com.kotasoft.training.roogwteclipselink.client.managed.activity.AsignaturaListActivity;
import com.kotasoft.training.roogwteclipselink.client.managed.request.AsignaturaProxy;
import com.kotasoft.training.roogwteclipselink.client.managed.ui.AsignaturaListView;
import com.kotasoft.training.roogwteclipselink.client.managed.ui.AsignaturaMobileListView;
import com.kotasoft.training.roogwteclipselink.client.managed.activity.AlumnoListActivity;
import com.kotasoft.training.roogwteclipselink.client.managed.request.AlumnoProxy;
import com.kotasoft.training.roogwteclipselink.client.managed.ui.AlumnoListView;
import com.kotasoft.training.roogwteclipselink.client.managed.ui.AlumnoMobileListView;

/**
 * Instantiates master activities.
 */
public final class ApplicationMasterActivities implements ActivityMapper {
	private final ApplicationRequestFactory requests;
	private final PlaceController placeController;

	@Inject
	public ApplicationMasterActivities(ApplicationRequestFactory requests, PlaceController placeController) {
 		this.requests = requests;
		this.placeController = placeController;
	}

	public Activity getActivity(Place place) {
		if (!(place instanceof ProxyListPlace)) {
			return null;
		}

		ProxyListPlace listPlace = (ProxyListPlace) place;

		return new ApplicationEntityTypesProcessor<Activity>() {
			@Override
      public void handleProfesor(ProfesorProxy isNull) {
        setResult(new ProfesorListActivity(requests,
          ScaffoldApp.isMobile() ? ProfesorMobileListView.instance() : ProfesorListView.instance(),
          placeController));
      }
      
			@Override
      public void handleMatricula(MatriculaProxy isNull) {
        setResult(new MatriculaListActivity(requests,
          ScaffoldApp.isMobile() ? MatriculaMobileListView.instance() : MatriculaListView.instance(),
          placeController));
      }
      
			@Override
      public void handleDireccion(DireccionProxy isNull) {
        setResult(new DireccionListActivity(requests,
          ScaffoldApp.isMobile() ? DireccionMobileListView.instance() : DireccionListView.instance(),
          placeController));
      }
      
			@Override
      public void handleDepartamento(DepartamentoProxy isNull) {
        setResult(new DepartamentoListActivity(requests,
          ScaffoldApp.isMobile() ? DepartamentoMobileListView.instance() : DepartamentoListView.instance(),
          placeController));
      }
      
			@Override
      public void handleAsignatura(AsignaturaProxy isNull) {
        setResult(new AsignaturaListActivity(requests,
          ScaffoldApp.isMobile() ? AsignaturaMobileListView.instance() : AsignaturaListView.instance(),
          placeController));
      }
      
			@Override
      public void handleAlumno(AlumnoProxy isNull) {
        setResult(new AlumnoListActivity(requests,
          ScaffoldApp.isMobile() ? AlumnoMobileListView.instance() : AlumnoListView.instance(),
          placeController));
      }
      
		}.process(listPlace.getProxyClass());
	}
}
